<?php

$path ="../ptnhuan-web1/data/films.txt";
$file_path =  realpath($path);
$rating1 = NULL;
$rating2 = NULL;
$films = array();

$file = fopen($file_path,"r");
while(!feof($file)){
    $films []= trim(fgets($file));
}
fclose($file);
?>

<form method="POST">
    From : <input type="text" name="rating1">
    To :   <input type="text" name="rating2">
    <input type="submit" name="submit" value="Search">
</form>
<?php  if (isset($_POST["submit"])): {
    $rating1 = intval($_POST["rating1"]);
    $rating2 = intval($_POST["rating2"]);
} ?>
<?php endif;?>

<?php 
foreach ($films as $item): ?>
<?php if(!empty($item)) :?>
<?php $film = explode(";", $item)?> 


  <?php if (isset($_GET['uid'])):?>
        <?php if ((int)$_GET['uid'] == (int)$film[4]):?>

 <?php if (empty($rating1) && empty($rating2)): ?>
<img src ='../ptnhuan-web1/public/images/films/<?php echo $film[1]?>'>
                <?php echo $film[2]?>
                <?php echo $film[3]?>
                <a href="edit_File.php?if=<?php echo $film[0]?>">  Edit</a>
<br>
<?php else: ?>

          <?php 
                $change = intval($film[3]);
           ?>

                <?php if(($change>=$rating1)&& ($change<=$rating2)): ?>
                <img src ='../ptnhuan-web1/public/images/films/<?php echo $film[1]?>'>
                <?php echo $film[2]?>
                <?php echo $film[3]?>
                <a href="edit_File.php?if=<?php echo $film[0]?>">  Edit</a>
<br>
<?php endif;?>
<?php endif;?>
<?php endif;?>
<?php endif;?>
<?php endif;?>
<?php endforeach; ?>


